<?php
include ("../init.php");
include('../includes/class.upload.php');

if(isset($_REQUEST['pid']) && $_REQUEST['pid']!=''){
	$project_id = $_REQUEST['pid'];
}else{
	$project_id = $_SESSION['ADDPROJECTID'];
}

if (!empty($_FILES)) {
	$tempFile = $_FILES['projectfiles']['tmp_name'];
	$handle = new Upload($_FILES['projectfiles']);
	
	if ( $handle->uploaded )
	{
	   $handle->image_resize = true;
	   $handle->image_ratio_fill = true;
	   $handle->image_x = 350;
	   $handle->image_y = 260;
	   $handle->Process('../../images/projects/'.$project_id);
	   
	   if ($handle->processed)
	   {
	     $sql = "INSERT INTO project_img VALUES(
	     '',
	     '$project_id',
	     '".$handle->file_dst_name."',
	     '1',
	     '100'
	     )";
	     
	     if(!mysql_query($sql))
	     {
	       @unlink('../../images/projects/'.$project_id.'/'.$handle->file_dst_name);
	     }
	   }
	   echo 0;
	   $handle->clean();
	}
	else
	{
	   $handle->clean();
	   echo 0;
	}
}
?>